package com.woniuxy.dr_mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.dr_mall.entity.DrSpec;
import com.woniuxy.dr_mall.entity.DrSpecPrice;
import com.woniuxy.dr_mall.entity.DrSpecVO;
import com.woniuxy.dr_mall.provider.SpecProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 张哲轩
 * @since 2021-08-11
 */
public interface DrSpecPriceMapper extends BaseMapper<DrSpecPrice> {
    /**
     * 根据商品id获取其价格信息
     *
     * @param pid 商品id
     * @return sku
     * @author yy
     * @since 2021-8-12 17:05
     */
    @Select("select * from dr_spec_price where productId=#{pid}")
    List<DrSpecPrice> getPriceByPid(int pid);

    @Select("select * from dr_spec_price where id=#{id}")
    @Results({
            @Result(column = "productId",property = "products",one = @One(
                    fetchType = FetchType.LAZY,
                    select = "com.woniuxy.dr_mall.mapper.DrProductsMapper.getProductById"
            ))
    })
    DrSpecPrice getSkusBySkuId(Integer id);

    /**
     * @return java.util.List<com.woniuxy.dr_mall.entity.DrSpecPrice>
     * @description:
     * @Author 张哲轩
     * @Date 2021/8/13 11:25
     */
    @SelectProvider(type = SpecProvider.class,method = "select")
    List<DrSpecPrice> getSkus(DrSpecVO specVO);

    @SelectProvider(type = SpecProvider.class,method = "selectVal")
    List<Integer> getAllValByColumn(DrSpec spec,int productId);


    //通过商品的id查询商品的价格 叶官鑫 2021-8-16
    @Select("select min(price) from dr_spec_price where productid=#{productId}")
    BigDecimal productIdSelectPrice(int productId);

    //通过specPriceId查specPrice的信息 叶官鑫 2021-8-17
    @Select("select* from dr_spec_price where id=#{specPriceId}")
    @Results({
            @Result(column = "weight",property = "weight"),
            @Result(column = "material",property = "material"),
            @Result(column = "color",property = "color"),
            @Result(column = "type",property = "type"),
            @Result(column = "size",property = "size"),
            @Result(column = "series",property = "series"),
            @Result(property = "weightN",column = "wight",one =@One( fetchType = FetchType.LAZY,select = "com.woniuxy.dr_mall.mapper.DrSpecValMapper.specidSelectSpecVal")),
            @Result(property = "materialN",column = "material",one =@One( fetchType = FetchType.LAZY,select = "com.woniuxy.dr_mall.mapper.DrSpecValMapper.specidSelectSpecVal" )),
            @Result(property = "colorN",column = "color",one =@One( fetchType = FetchType.LAZY,select = "com.woniuxy.dr_mall.mapper.DrSpecValMapper.specidSelectSpecVal")),
            @Result(property = "typeN",column = "type",one =@One( fetchType = FetchType.LAZY,select = "com.woniuxy.dr_mall.mapper.DrSpecValMapper.specidSelectSpecVal" )),
            @Result(property = "sizeN",column = "size",one =@One( fetchType = FetchType.LAZY,select = "com.woniuxy.dr_mall.mapper.DrSpecValMapper.specidSelectSpecVal")),
            @Result(property = "seriesN",column = "series",one =@One( fetchType = FetchType.LAZY,select = "com.woniuxy.dr_mall.mapper.DrSpecValMapper.specidSelectSpecVal" ))
    })
    DrSpecPrice selectSpecPriceImformation(int specPriceId);

}
